package com.mc.mq.rocketmq.batch;

import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.SendStatus;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

public class Producer {
    public static void main(String[] args) throws MQClientException, MQBrokerException, RemotingException, InterruptedException {
        DefaultMQProducer producer=new DefaultMQProducer("group1");
        producer.setNamesrvAddr("192.168.3.31:9876;192.168.3.32:9876;");
        producer.start();

        List<Message> msgs=new ArrayList<>();

        Message msg1=new Message("BatchTopic","Tag1",("Hello"+1).getBytes(StandardCharsets.UTF_8));
        Message msg2=new Message("BatchTopic","Tag1",("Hello"+2).getBytes(StandardCharsets.UTF_8));
        Message msg3=new Message("BatchTopic","Tag1",("Hello"+3).getBytes(StandardCharsets.UTF_8));

        msgs.add(msg1);
        msgs.add(msg2);
        msgs.add(msg3);

        SendResult result = producer.send(msgs);
        SendStatus status = result.getSendStatus();
        producer.shutdown();
    }

}
